package com.open.party.cloud.view.home.renCaiGongZuo

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import cn.android.x.parent.AppTitleBaseActivity
import com.open.party.cloud.R
import com.open.party.cloud.view.home.article.fragment.ArticleListFragment
import com.open.party.cloud.view.home.ziShenJiaoYu.fragments.LeaderListFragment
import kotlinx.android.synthetic.main.title_tab_view_page_av.*

class ZhuanJiaMainActivity : AppTitleBaseActivity() {

    override fun getLayoutResId(): Int = R.layout.title_tab_view_page_av

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setViewTitle("专家服务")
        initTabView()
    }

    private fun initTabView() {
        val titleList = ArrayList<String>()
        val fragmentList = ArrayList<Fragment>()

        titleList.add("专家服务")
//        titleList.add("专家服务脱贫攻坚")
        fragmentList.add(LeaderListFragment())

//        val fragment2 = ArticleListFragment()
//        val bundle2 = Bundle()
//        // RCGZ_ZJFC
//        bundle2.putString("type", "RCGZ_ZJFWTPGJ")
//        fragment2.arguments = bundle2
//        fragmentList.add(fragment2)

        initTab(titleList, fragmentList)
    }

    private fun initTab(titles: ArrayList<String>, fragments: List<Fragment>) {

        val fragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(arg0: Int): Fragment {
                return fragments[arg0]
            }
        }

        viewPager.offscreenPageLimit = titles.size - 1
        viewPager.adapter = fragmentPagerAdapter
        //        pager.addOnPageChangeListener(this);

        scrollTab.setTitles(titles)
//        scrollTab.setNumber(1, "9", View.VISIBLE)//设置数字红点
        scrollTab.setViewPager(viewPager)
        scrollTab.setOnTabListener { index, _ ->
            viewPager.setCurrentItem(index, true)
        }

        scrollTab.visibility = View.GONE
    }
}